// html 模板指定
// commenjs 引入方式 - node 后端运行方式
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const basePath = __dirname;

module.exports = {
  // 目录上下文环境
  context: path.join(basePath, "src"),
  resolve: {
    // 处理 拓展名
    extensions: [".js", ".ts", ".tsx"],
    alias: {
      "@": path.resolve(__dirname, "src"),
      "~": path.resolve(__dirname, "src/assets"),
    },
  },
  entry: {
    app: ["./main.tsx"],
  },
  output: {
    filename: "[name].[chunkhash].js",
  },
  mode: "development",
  devServer: {
    hot: true,
    open: true,
    port: 1314,
  },
  module: {
    rules: [
      {
        //
        test: /\.tsx?$/,
        // 排除
        exclude: /node_modules/,
        // 加载器
        loader: "babel-loader",
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          {
            //   样式 处理
            loader: "style-loader",
          },
          {
            //   css 处理
            loader: "css-loader",
          },
        ],
      },
    ],
  },
  // 插件
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "index.html",
    }),
  ],
};
